package ArrayList

type StackArray interface {
	Clear()                //清空
	Size() int             //大小
	Pop() interface{}      //弹出
	Push(data interface{}) //压入
	IsFull() bool          //是否满了
	IsEmpty() bool         //是否为空
}

type Stack struct {
	myarray List //数组
	capsize int  //最大范围
}

func NewArrayListStack() StackArray {
	stack := new(Stack)
	stack.myarray = NewArrayList()
	stack.capsize = 10
	return stack
}

func (s *Stack) Clear() {
	s.myarray.Clear()
	s.capsize = 10
}

func (s *Stack) Size() int {
	return s.myarray.Size()
}

func (s *Stack) Pop() interface{} {
	if !s.IsEmpty() {
		last := s.myarray.Last()               //最后一个数据
		s.myarray.Delete(s.myarray.Size() - 1) //删除最后一个
		return last
	}
	return nil
}

func (s *Stack) Push(data interface{}) {
	if !s.IsFull() {
		s.myarray.Append(data)
	}
}

func (s *Stack) IsFull() bool {
	if s.myarray.Size() >= s.capsize {
		return true
	}
	return false
}

func (s *Stack) IsEmpty() bool {
	if s.myarray.Size() == 0 {
		return true
	}
	return false
}
